package com.panfeng.xcloud.boss.provider.member.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.panfeng.xcloud.boss.provider.member.service.ISlidingVerificationService;
import com.panfeng.xcloud.boss.provider.member.web.vo.request.SlidingVerificationReqVO;
import com.panfeng.xcloud.boss.provider.member.web.vo.response.SlidingVerificationRespVO;
import com.panfeng.xcloud.common.core.utils.ConvertUtils;
import com.panfeng.xcloud.common.core.web.vo.ResponseVO;
import com.panfeng.xcloud.common.security.annotation.MethodValidate;
import com.panfeng.xcloud.common.security.annotation.NotNeedAccess;
import com.panfeng.xcloud.common.security.web.support.BaseController;
import com.panfeng.xcloud.component.ocr.model.SlidingVerificationReqDTO;
import com.panfeng.xcloud.component.ocr.model.SlidingVerificationRespDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

/**
 * 阿里滑动验证模块
 *
 * @author xiaobo
 * @version 1.0
 * @since 2019-08-08
 */
@ApiIgnore
@RestController
@RequestMapping("user/aliyun")
@Api(tags = {"阿里滑动验证模块"})
@Slf4j
public class UserSlidingVerifyController extends BaseController {

    @Autowired
    private ISlidingVerificationService iSlidingVerificationService;

    /**
     * 滑动验证
     *
     * @param slidingVerificationReqVO
     * @param bindingResult
     * @return
     */
    @MethodValidate
    @NotNeedAccess
    @PostMapping(value = "/slidingVerification", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "滑动验证(肖博)", httpMethod = "POST", notes = "滑动验证(肖博)")
    public ResponseVO<SlidingVerificationRespVO> slidingVerification(
            @ApiParam(value = "滑动验证参数", required = true) @RequestBody @Valid SlidingVerificationReqVO slidingVerificationReqVO,
            BindingResult bindingResult) {
        logger.info(">>>> 当前slidingVerification请求参数：{} <<<", (null != slidingVerificationReqVO ? JSONObject.toJSONString(slidingVerificationReqVO) : ""));
        SlidingVerificationReqDTO slidingVerificationReqDTO = ConvertUtils.convert(slidingVerificationReqVO, SlidingVerificationReqDTO.class);
        SlidingVerificationRespDTO slidingVerificationRespDTO = iSlidingVerificationService.slidingVerification(slidingVerificationReqDTO);
        SlidingVerificationRespVO slidingVerificationRespVO = ConvertUtils.convert(slidingVerificationRespDTO, SlidingVerificationRespVO.class);
        logger.info(">>>> 当前slidingVerification响应内容：{} <<<", (null != slidingVerificationRespVO ? JSONObject.toJSONString(slidingVerificationRespVO) : ""));
        return ResponseVO.with(slidingVerificationRespVO);
    }

}
